layui.config(
{
	base: "../../js/ENV-INFO/"
}).use(['jquery', 'eleTree'], function()
{
	var $ = layui.jquery;
	var eleTree = layui.eleTree;

	var data2 = [
	{
		"label": "a",
		"spread": true,
		"children": [
		{
			"label": "aa1",
		},
		{
			"label": "bb1",
		},
		{
			"label": "cc1"
		}]
	},
	{
		"label": "c",
		"children": [
		{
			"label": "aa1",
		},
		{
			"label": "bb1",
		}]
	}];

	eleTree.render(
	{
		elem: '.ele2',
		// url: "../../data/home/tree.json",
		// type: "post",
		data: data2,
		showCheckbox: true,
		contextmenuList: ["add", "remove"],
		drag: true,
		accordion: true
	});

	eleTree.on("add(data1)", function(data)
	{
		console.log(data);
		// 若后台修改，则重新获取后台数据，然后重载
		// eleTree.reload(".ele1", {where: {data: JSON.stringify(data.data)}})
	})
	eleTree.on("edit(data1)", function(data)
	{
		console.log(data);
	})
	eleTree.on("remove(data1)", function(data)
	{
		console.log(data);
	})
	eleTree.on("toggleSlide(data1)", function(data)
	{
		console.log(data);
	})
	eleTree.on("checkbox(data1)", function(data)
	{
		console.log(data);
	})
	eleTree.on("drag(data2)", function(data)
	{
		console.log(data);
	})
	$(".test-select").on("click", function()
	{
		console.log(111);
		if ($(".test-tree").hasClass("layui-anim"))
		{
			$(".test-tree").hide();
			$(".test-tree").removeClass("layui-anim-upbit");
			$(".test-tree").removeClass("layui-anim");
		}
		else
		{
			$(".test-tree").show();
			$(".test-tree").addClass("layui-anim-upbit");
			$(".test-tree").addClass("layui-anim");
		}
	})
	$(".layui-btn").on("click", function()
	{
		// console.log(eleTree.checkedData(".ele2"));
		var datalist = eleTree.checkedData(".ele2");
		var sel_val = "";
		for (var i = 0; i < datalist.length; i++)
		{
			console.log(datalist[i].label);
			if (!datalist[i].children)
			{
				sel_val += datalist[i].label + ",";
				// console.log(sel_val);
			}
		}
		$(".test-select").val(sel_val);
		$(".test-tree").css("opacity", "0");
		$(".test-tree").hide();
		$(".test-tree").removeClass("layui-anim-upbit");
		$(".test-tree").removeClass("layui-anim");
	})

});

layui.use(['form', 'table'], function(){
	// 引用各模块方法
	var form = layui.form;
	var table = layui.table;

	//表格配置
	var tableID = 'table'
	table.render({
		// 选择器
		elem: '#' + tableID,
		// 高度
		height: auto_height,
		// 宽度
		// width: 720,
		// 单元格最小宽度(默认60)
		// cellMinWidth: 120,
		// 样式
		even: true,
		// 开启分页
		page: true,
		// 显示加载条
		loading: true,
		// 工具栏
		toolbar: '#toolbar',
		// 工具栏右侧功能(设置为空Array的时候将隐藏，需要显示该功能只要注释掉这项就好)
		defaultToolbar: ['filter', 'exports'],
		// 数据接口
		url: API_HEAD + '/vwweatheralarm/',
		// 接口http请求类型
		method: 'get',
		// 分页请求的参数，重新设定名称
		request: {
			pageName: 'pageIndex',
			limitName: 'pageSize'
		},
		// 数据格式，重新规定返回的数据格式
		response: {
			statusCode: 200,
			msgName: 'msg',
			countName: 'pageTotal',
			dataName: 'data'
		},
		// 表头
		cols: [[
			{type:'checkbox'},
			{field:'id', width:100, title: 'ID', sort: true},
			{field:'username', width:100, title: '用户名'},
			{field:'sex', width:100, title: '性别', sort: true},
			{field:'city', width:100, title: '城市'},
			{field:'sign', title: '签名', minWidth: 100},
			{field:'experience', width:100, title: '积分', sort: true},
			{field:'score', width:100, title: '评分', sort: true},
			{field:'classify', width:100, title: '职业'},
			{field:'wealth', width:135, title: '财富', sort: true},
		]],
	});

	// 根据窗口尺寸自适应高度
	$(window).resize(function(){
		table.reload(tableID, {
			// 高度
			height: $(window).height() - $('#js-searchTool').height() - 100,
		});
	})

	//监听工具条
	table.on('toolbar(' + tableID + ')', function(obj) {
		//获得 lay-event 对应的值
		var layEvent = obj.event;
		// 判断情况
		if (layEvent === 'add') { //添加
			console.log("添加");
			//do somehing
		}
		else if (layEvent === 'delete') { //删除
			layer.confirm('真的删除行么', function(index){
				console.log("删除");
				// //向服务端发送删除指令
				// obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
				layer.close(index);
			});
		}
		else if (layEvent === 'update') { //编辑
			console.log("编辑");
			// //do something
			//
			// //同步更新缓存对应的值
			// obj.update({
			//   username: '123'
			//   ,title: 'xxx'
			// });
		}
		else if (layEvent === 'search') { //编辑
			console.log("查找");
			// //do something
			layer.alert('查询条件弹窗')
		}
	});

	// //重载表格
	// var tableObj = table.render({});
	// tableObj.reload(options);
});

//自适应高度
var auto_height = $(window).height() - $('#js-searchTool').height() - 100
